//
//  LRXDistributionFirstCell.m
//  路人侠
//
//  Created by zhangxulong on 4/4/16.
//  Copyright © 2016 zhangxulong. All rights reserved.
//

#import "LRXDistributionFirstCell.h"
@interface LRXDistributionFirstCell()

@property (nonatomic,strong) UIImageView * userIcon;
@property (nonatomic,copy) UILabel * chatLabel;
@property (nonatomic,strong) UIButton * preferenceBtn;
@end

@implementation LRXDistributionFirstCell
- (UIImageView *)userIcon
{
    if (_userIcon == nil) {
        _userIcon = [[UIImageView alloc]init];
    }
    return _userIcon;
}
- (UILabel *)chatLabel
{
    if (_chatLabel == nil) {
        _chatLabel = [[UILabel alloc]init];
    }
    return _chatLabel;
}
- (UIButton *)preferenceBtn
{
    if (_preferenceBtn == nil) {
        _preferenceBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    }
    return _preferenceBtn;
}
- (void)layoutDistributionFirstCell:(NSDictionary *)cellInfo
{
    self.selectionStyle = UITableViewCellSeparatorStyleNone;
    self.backgroundColor = [UIColor colorWithRed:247 green:246 blue:246];
    
    NSURL * imageUrl = [NSURL URLWithString:[routeImageUrl stringByAppendingString:cellInfo[@"profile_url"]]];
    [self.userIcon sd_setImageWithURL:imageUrl placeholderImage:[UIImage imageNamed:@"de"]];
    self.userIcon.frame = CGRectMake(16 * wScale, 16 * hScale, 68 * hScale, 68 * hScale);
    self.userIcon.layer.cornerRadius = self.userIcon.frame.size.width * 0.5;
    self.userIcon.layer.masksToBounds = YES;
    
    self.chatLabel.text = cellInfo[@"chat"];
    self.chatLabel.font = [UIFont systemFontOfSize:25 * hScale];
    self.chatLabel.textColor = mainColor;
    self.chatLabel.frame = CGRectMake(CGRectGetMaxX(self.userIcon.frame) + 25 * wScale, 35 * hScale, 0, 0);
    [self.chatLabel sizeToFit];
    
    
    self.preferenceBtn.frame = CGRectMake(MainScreenW - (16 + 40) * wScale, 35 * hScale, 40 * hScale, 40 * hScale);
    [self.preferenceBtn setImage:[UIImage imageNamed:@"nolove"] forState:UIControlStateNormal];
    [self.preferenceBtn setImage:[UIImage imageNamed:@"love"] forState:UIControlStateSelected];
    [self.preferenceBtn addTarget:self action:@selector(preferenceBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    
    [self addSubview:self.userIcon];
    [self addSubview:self.chatLabel];
    [self addSubview:self.preferenceBtn];
    
}
- (void)preferenceBtnClick:(UIButton *)preferenceBtn
{
    preferenceBtn.selected = !preferenceBtn.selected;
}


@end
